#include <rclcpp/rclcpp.hpp>

class TargetNode : public rclcpp::Node {
public:
  TargetNode() : Node("target_node") {
    RCLCPP_INFO(this->get_logger(), "目标节点已启动，提供以下参数:");
    RCLCPP_INFO(this->get_logger(), "  - max_speed (double)");
    RCLCPP_INFO(this->get_logger(), "  - debug_mode (bool)");
    RCLCPP_INFO(this->get_logger(), "  - sensor_timeout (int)");

    // 声明参数并设置默认值
    this->declare_parameter("max_speed", 2.0);
    this->declare_parameter("debug_mode", false);
    this->declare_parameter("sensor_timeout", 500);

    // 参数变更回调示例
    this->add_on_set_parameters_callback(
        [this](const std::vector<rclcpp::Parameter> &params) {
          for (const auto &param : params) {
            RCLCPP_INFO(this->get_logger(), "参数被修改: %s = %s",
                        param.get_name().c_str(),
                        param.value_to_string().c_str());
          }
          // 必须返回成功/失败结果
          rcl_interfaces::msg::SetParametersResult result;
          result.successful = true;
          return result;
        });
  }
};

int main(int argc, char **argv) {
  rclcpp::init(argc, argv);
  auto node = std::make_shared<TargetNode>();
  rclcpp::spin(node);
  rclcpp::shutdown();
  return 0;
}